<html>
<head><meta charset="utf-8"><title>Why does AtomicPtr&lt;T&gt; needs a * const T · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20does.20AtomicPtr.3CT.3E.20needs.20a.20*.20const.20T.html">Why does AtomicPtr&lt;T&gt; needs a * const T</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="230097998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20does%20AtomicPtr%3CT%3E%20needs%20a%20%2A%20const%20T/near/230097998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20does.20AtomicPtr.3CT.3E.20needs.20a.20*.20const.20T.html#230097998">(Mar 12 2021 at 21:09)</a>:</h4>
<p>Hello!<br>
I wonder why <code>AtomicPtr&lt;T&gt;</code> requires a <code>*mut T</code> and not a <code>* const T</code>?</p>



<a name="230098071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20does%20AtomicPtr%3CT%3E%20needs%20a%20%2A%20const%20T/near/230098071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20does.20AtomicPtr.3CT.3E.20needs.20a.20*.20const.20T.html#230098071">(Mar 12 2021 at 21:10)</a>:</h4>
<p>You can freely cast between those types so it doesn't really matter.</p>



<a name="230098126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20does%20AtomicPtr%3CT%3E%20needs%20a%20%2A%20const%20T/near/230098126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20does.20AtomicPtr.3CT.3E.20needs.20a.20*.20const.20T.html#230098126">(Mar 12 2021 at 21:10)</a>:</h4>
<p>Or rather should there be a AtomicConstPtr?</p>



<a name="230100340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20does%20AtomicPtr%3CT%3E%20needs%20a%20%2A%20const%20T/near/230100340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20does.20AtomicPtr.3CT.3E.20needs.20a.20*.20const.20T.html#230100340">(Mar 12 2021 at 21:27)</a>:</h4>
<p>that would <em>likely</em> be incorrect. usually const pointers come from shared references and/or read-only memory.</p>



<a name="230110995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20does%20AtomicPtr%3CT%3E%20needs%20a%20%2A%20const%20T/near/230110995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20does.20AtomicPtr.3CT.3E.20needs.20a.20*.20const.20T.html#230110995">(Mar 12 2021 at 22:36)</a>:</h4>
<p>What's the point of an immutable atomic pointer? You can just use <code>&amp;T</code> for that</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>